package cn.codingjc.peekaboo.application.service.sql.impl;

import cn.codingjc.peekaboo.application.core.pipeline.ProcessContext;
import cn.codingjc.peekaboo.application.core.pipeline.ProcessController;
import cn.codingjc.peekaboo.application.core.sql.param.SqlSchemaParam;
import cn.codingjc.peekaboo.application.service.sql.SqlService;
import cn.codingjc.peekaboo.domain.common.enums.ProcessContextCodeEnum;
import cn.codingjc.peekaboo.domain.domain.sql.dto.TableSchemaDTO;
import cn.codingjc.peekaboo.domain.domain.sys.vo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @date: 2023/5/4
 * @author: Codingjc
 * @className: SqlServiceImpl
 **/

@Slf4j
@Service
public class SqlServiceImpl implements SqlService {

    @Autowired
    ProcessController processController;

    @Override
    public ResultVO generateSchema(TableSchemaDTO tableSchemaDTO) {
        // 1.校验
        // 2.构造建表 SQL
        // 3.生成模拟数据
        // 4.生成插入 SQL
        // 5.生成数据 json
        // 6.生成 java 实体代码
        // 7.生成 java 对象代码
        // 8.生成 typescript 类型代码
//        validSchema(tableSchemaDTO);
        ProcessContext processContext = ProcessContext
                .builder()
                .code(ProcessContextCodeEnum.GENERATE_SQL.getCode())
                .processParam(new SqlSchemaParam(tableSchemaDTO))
                .needBreak(false)
                .build();
        ProcessContext process = processController.process(processContext);
        return process.getResult();
    }
}
